package net.tv90.bfmccoreqqbot.api.handler;

import net.tv90.bfmccore.api.info.PlayerStatistic;
import net.tv90.bfmccoreqqbot.api.MessageHandler;
import net.tv90.bfmccoreqqbot.api.annotation.MessageCheck;
import net.tv90.bfmccoreqqbot.api.annotation.MessageCheckPolicy;
import net.tv90.bfmccoreqqbot.api.annotation.MessageType;
import net.tv90.bfmccoreqqbot.api.entity.MessageContext;

@MessageType("查询武器")
@MessageCheck(MessageCheckPolicy.STARTS_WITH)
public class WeaponInfoMessageHandler implements MessageHandler {

    @Override
    public String handleMessage(MessageContext msg) {

        String[] args = msg.getMessage().split("=");

        if (args.length == 3) {
            try {
                String playerName = args[1];
                String page = args[2];
                return PlayerStatistic.getWeaponInfo(playerName, Integer.parseInt(page), 20);
            } catch (Exception e) {
                return "格式有误，格式: 查询武器=玩家名=页码，如 查询武器=TV90=1";
            }
        }
        return "格式有误，格式: 查询武器=玩家名=页码，如 查询武器=TV90=1";
    }
}
